import { createSSRApp } from 'vue'

import App from './App.vue'
import plugins from './plugins'
import { setupRouter } from './router'
import './styles/index.scss'
import * as Pinia from 'pinia'
import piniaPluginPersist from 'pinia-plugin-persist'

// 国际化
import { i18n } from '../locale/index'
// 全局方法
import {
    currencySymbol,
    amountFormat,
    stateFormat,
    langFormat,
    trim,
    distanceFormat,
    joinFormat,
    jump,
    backup,
    callPhone,
    getImg,
    getMenuButtonTop,
    getWindowHeight
} from '@/utils/util'

// 语言
export const languages: Languages[] = [
    { text: '中文', value: 'zh-cn', iconfont: 'icon-fuhao-zhongwen' },
    { text: 'English', value: 'en', iconfont: 'icon-fuhao-yingwen' }
    // {text: 'Français', value: 'fr', iconfont: 'icon-fuhao-yingwen'},
]

export function createApp() {
    const app = createSSRApp(App)

    app.config.globalProperties.$languages = languages
    app.config.globalProperties.$currencySymbol = currencySymbol
    app.config.globalProperties.$amountFormat = amountFormat
    app.config.globalProperties.$stateFormat = stateFormat
    app.config.globalProperties.$langFormat = langFormat
    app.config.globalProperties.$trim = trim
    app.config.globalProperties.$distanceFormat = distanceFormat
    app.config.globalProperties.$joinFormat = joinFormat
    app.config.globalProperties.$jump = jump
    app.config.globalProperties.$backup = backup
    app.config.globalProperties.$callPhone = callPhone
    app.config.globalProperties.$getImg = getImg
    app.config.globalProperties.$fileUrl = import.meta.env.VITE_APP_BASE_URL
    app.config.globalProperties.$getMenuButtonTop = getMenuButtonTop
    app.config.globalProperties.$getWindowHeight = getWindowHeight

    Promise.resolve().then(() => {
        setupRouter()
    })
    app.use(plugins)
    return {
        app
    }
}
